package 代码记录.Bit48天集训;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

/**1.字符串中找出连续最长的数字串
 * 2.最小的K个数
 * 3.餐馆
 * @author zx
 * @create 2022-07-11 15:59
 */
public class Last {
    /**
     * 贪心算法
     * 算法思想：用max表示经过的数字长度最大值,count表示数字计数器,当为字母时重置为0
     * end表示数字尾部,每次满足数字时,对max进行判断,当max小于于count时,更新max和end
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String str = scanner.nextLine();
            int max = 0, count = 0, right = 0;
            for (int i = 0; i < str.length(); i++) {
                if (str.charAt(i) >= '0' && str.charAt(i) <= '9') {
                    count++;
                    if (max < count) {
                        max = count;
                        right = i;
                    }
                } else {
                    count = 0;
                }
            }
            System.out.println(str.substring(right - max + 1, right + 1));
        }
    }

    /**
     * @return 最大堆
     */
    public ArrayList<Integer> GetLeastNumbers_Solution (int[] input, int k) {
        ArrayList<Integer> res = new ArrayList<>();
        if(input.length == 0 || k == 0){
            return res;
        }
        PriorityQueue<Integer> queue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;//改造为最大堆
            }
        });
        for(int i = 0;i < input.length;i++){
            if(queue.size() < k){
                queue.offer(input[i]);
            }else{
                int peek = queue.peek();
                if(input[i] > peek){
                    continue;
                }else{
                    queue.poll();
                    queue.offer(input[i]);
                }
            }
        }
        for(int i = 0;i < k;i++){
            res.add(queue.poll());
        }
        return res;
    }
}
